<?php

namespace GamesBundle\Services;
use GamesBundle\Entity\GameAwards;
use GamesBundle\Entity\GameNperRecord;
use GamesBundle\Entity\GamesUserOrder;
use GamesBundle\Services\ContainerAware;

/**
 *
 * 数据匹配
 * @author  coffey  <coffey@nligo.com>
 * @time    2017/2/21
 */
class MatchLottery extends ContainerAware
{
    /**
     * @auhtor  coffey
     *
     * 匹配排名中奖（123/123/200）这种
     * @param int $gameId
     * @param string $str
     * @param array $GameNperRecordIdInfo
     * @return array
     */
    public function matchLot($nper = 0)
    {
        $result['code'] = 0;
        $result['data'] = '';
        $doctrine = $this->container->get('doctrine');
        $em = $doctrine->getManager();
        $lotlist = $em->getRepository('GamesBundle:GamesUserOrder')->loadValidOrder($nper,1);
        if(!empty($lotlist))
        {
            foreach ($lotlist as $k=>$v)
            {
                if($v->getGameType() == 1)
                {
                    $lot_str = $v->getGameNperRecordId()->getLotNumber();
                }
                if($v->getGameType() == 2)
                {
                    $lot_str = $v->getGameNperRecordId()->getFileds();
                }

                if(in_array($v->getGameTypeName(),explode(',',$lot_str)))
                {
                    $gameAw = new GameAwards();
                    $gameAw->setOrderId($v);
                    $gameAw->setGameNperRecordId($v->getGameNperRecordId());
                    $em->persist($gameAw);
                    $em->flush($gameAw);
                }
            }
        }
        return $result;

    }
}